package com.fsj.miniapp.service.impl;

import com.fsj.miniapp.dao.GoodsBasicInfoDao;
import com.fsj.miniapp.entity.GoodsBasicInfo;
import com.fsj.miniapp.service.GoodsBasicInfoService;
import com.fsj.miniapp.vo.GoodsBasicInfoVo;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GoodsBasicInfoServiceImpl extends BaseService<GoodsBasicInfo, BaseExample, Long> implements GoodsBasicInfoService {

    @Autowired
    private GoodsBasicInfoDao goodsBasicInfoDao;
    @Override
    public GoodsBasicInfoVo getById(Long goodsId) {
        BaseExample exam = new BaseExample();
        exam.createCriteria().addCriterion("goods_id=", goodsId);
        List<GoodsBasicInfo> goodsBasicInfos = goodsBasicInfoDao.selectByExampleWithBLOBs(exam);
        if (!CollectionUtils.isEmpty(goodsBasicInfos)) {

            return goodsBasicInfos.stream().map(f -> {
                GoodsBasicInfoVo vo = new GoodsBasicInfoVo();
                BeanUtils.copyProperties(f, vo);
                return vo;
            }).collect(Collectors.toList()).get(0);
        }
        return new GoodsBasicInfoVo();
    }
}